home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Networking / OT PAPServerSample / EnableSelfSendSample.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-28  |  3.3 KB  |  101 lines  |  [TEXT/CWIE]

  1. /*
  2.     File: EnableSelfSendSample.c
  3.     By:        Rich Kubota
  4.             Developer Technical Support
  5.     
  6.     Purpose: Demonstrate the use of the OTOptionManagement call to tell an AppleTalk
  7.             endpoint to enable/disable the SelfSend option.
  8.     change history:
  9.             1/25/98    rrk Changed the original use of the OTOptionManagement call, OPT_SELFSEND
  10.                 which only enables selfsend from the endpoint to other AppleTalk services when
  11.                 broadcast messages are sent from the endpoint.  The desired behavior is one 
  12.                 where if other AppleTalk clients on the node send broadcast messages, that they
  13.                 are also sent to the endpoint.  To this end, there is the ATALK_IOC_FULLSELFSEND
  14.                 Ioct, which must be sent to the DDP endpoint.
  15.                 
  16.                 Note that the ATALK_IOC_FULLSELFSEND is desired to respond similarly to the 
  17.                 PSetSelfSend function.  If the result is not negative, then the following responses
  18.                 can be expected.
  19.                 
  20.                 0 - FullSelfSend was previously off
  21.                 1 - FullSelfSend was previously on
  22.                 
  23.                 Input parameters
  24.                 
  25.                 ep - the AppleTalk EndpointRef on which to enable fullSelfSend. You can pass
  26.                 any AppleTalk endpoint, DDP or above, to this function.
  27.                 
  28.                 enableSelfSend - a long word of the desired setting.
  29.                 
  30.                 Return result
  31.                 < 0 - error
  32.                 0 - FullSelfSend was previously off
  33.                 1 - FullSelfSend was previously on
  34.                 
  35.                 Note that if the use of the Ioctl returns an error < 0, then the PBSetSelfSend
  36.                 function is called.
  37.                 
  38.                 Note: As with the PSetSelfSend call, the Ioctl call affects AppleTalk globally.
  39.                 If you enable this feature, it is recommended that you not disable the feature
  40.                 when the process quits.  The user may launch another process which enables 
  41.                 selfsend.  Turning off selfsend in this case, affects the other process, as well.
  42. */
  43.  
  44. #include "OpenTransport.h"            // open transport files            
  45. #include "OpenTptAppletalk.h"
  46. #include "AppleTalk.h"
  47.  
  48. extern OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend);
  49.  
  50.  
  51. /*
  52.     Sample function to enable/disable the SelfSend option for 
  53.     an AppleTalk endpoint. 
  54.  
  55.     Input
  56.     EndpointRef ep - endpoint on which to set SelfSend option on
  57.     long enableSelfSend - 1L - option on, 0L - option off
  58.  
  59.    Return: kOTNoError indicates that the option was successfully negotiated
  60.                otherwise the error result is returned
  61.  
  62.     IMPORTANT NOTE: if you find that this sample fails to enable/disable self send, check
  63.             the file OpenTptAppleTalk.h and ensure that ATALK_IOC_FULLSELFSEND is defined 
  64.             as follows
  65.             
  66.         #define ATALK_IOC_FULLSELFSEND            MIOC_CMD(MIOC_ATALK,47)
  67.         
  68.             there are versions of the header file that incorrectly define 
  69.             ATALK_IOC_FULLSELFSEND as follows.
  70.             
  71.         #define ATALK_IOC_FULLSELFSEND            MIOC_CMD(MIOC_ATALK,47) // INCORRECT
  72.             
  73.  
  74.     
  75. */
  76. OSStatus DoNegotiateSelfSendOption(EndpointRef ep, long enableSelfSend)
  77.  
  78. {
  79.     OSStatus        result;
  80.     SetSelfparms    pb;
  81.     Boolean            usePB = false;
  82.     
  83.     if (OTIsSynchronous(ep) == false)            // check whether ep sync or not
  84.         usePB = true;
  85.     else
  86.     {
  87.         result = OTIoctl(ep, ATALK_IOC_FULLSELFSEND, (void*)enableSelfSend);
  88.         if (result < kOTNoError)
  89.             usePB = true;    // if an error occured, try using the PBSetSelfSend call
  90.     }
  91.     
  92.     if (usePB == true)
  93.     {
  94.         pb.newSelfFlag = enableSelfSend != 0 ? true : false;  /* set self send option */
  95.         result = PSetSelfSend((MPPPBPtr) &pb, false);
  96.         
  97.     }
  98.         
  99.     return result;
  100. }
  101.